package com.zxl.diy.weather.location;

import android.content.Context;
import android.location.Location;

/**
 * 基础定位
 * Created by Administrator on 2016/11/5.
 */
public abstract class BaseLocationHelper implements OnLocationStatusListener {

    protected Context mContext;

    private boolean mIsCancel;

    private OnLocationStatusListener mOnLocationStatusListener;

    public BaseLocationHelper(Context mContext, OnLocationStatusListener mOnLocationStatusListener) {
        this.mContext = mContext;
        this.mOnLocationStatusListener = mOnLocationStatusListener;
    }

    public void startLocation() {
        mIsCancel = false;
    }

    public void cancel() {
        mIsCancel = true;
        if (null != mOnLocationStatusListener) {
            mOnLocationStatusListener.onLocationFailed(LOCATION_TIME_OUT);
        }
    }

    @Override
    public void onLocationFailed(int status) {
        if (null != mOnLocationStatusListener && !mIsCancel) {
            mOnLocationStatusListener.onLocationFailed(status);
        }
    }

    @Override
    public void onLocationSuccess(Location curLocation) {
        if (null != mOnLocationStatusListener && !mIsCancel) {
            mOnLocationStatusListener.onLocationSuccess(curLocation);
        }
    }
}
